package com.sen.design.pattern.creational.prototype.clone;

import java.util.Date;

public class Pig {

    private String name;
    private Date birthday;

    public Pig(String name, Date birthday) {
        this.name = name;
        this.birthday = birthday;
    }

    public String getName() {
        return name;
    }

    public void setName(String name) {
        this.name = name;
    }

    public Date getBirthday() {
        return birthday;
    }

    public void setBirthday(Date birthday) {
        this.birthday = birthday;
    }

    @Override
    protected Object clone() throws CloneNotSupportedException {
        Pig clone = (Pig) super.clone();
        // 深克隆：当对象里含有其他对象时，要注意原型模式的克隆问题；
        clone.birthday = (Date) clone.getBirthday().clone();
        return clone;
    }

    @Override
    public String toString() {
        return "Pig{" +
                "name='" + name + '\'' +
                ", birthday=" + birthday +
                '}';
    }
}
